// 待发货订单
<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="searchMsg">
				<el-form-item>
					<el-input v-model="searchMsg.orderNo" placeholder="请输入订单编号搜索" clearable></el-input>
				</el-form-item>
				<el-form-item>
					<el-input v-model="searchMsg.contactPhone" placeholder="请输入联系电话搜索" clearable></el-input>
				</el-form-item>
				<!-- <el-form-item>
					<el-input v-model="searchMsg.contactRealname" placeholder="请输入联系人姓名搜索" clearable></el-input>
				</el-form-item>               
				<el-form-item>
					<el-input v-model="searchMsg.fullReductionRuleDescription" placeholder="请输入满减规则名称搜索" clearable></el-input>
				</el-form-item>     
				<el-form-item>
					<el-input v-model="searchMsg.couponsDescription" placeholder="请输入优惠卷名称搜索" clearable></el-input>
				</el-form-item>     
				<el-form-item>
					<el-input v-model="searchMsg.contactStreet" placeholder="请输入收货地址搜索" clearable></el-input>
				</el-form-item>          -->
				<el-form-item label="">
					<el-date-picker v-model="searchMsg.createTime" type="daterange" align="right" unlink-panels
						range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"
						:picker-options="pickerOptions">
					</el-date-picker>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="getList(1)">查询</el-button>
				</el-form-item>
			</el-form>
		</el-col>
		<!--列表-->
		<el-table ref="table" :data="list" highlight-current-row v-loading="listLoading" style="width: 100%;"
			:cell-style="cellStyle" :header-cell-style="headerCellStyle">
			<!-- <el-table-column type="index" label="序号" width="50">
				<template scope="scope">
					<span>{{(searchMsg.pageNo - 1) * searchMsg.pageSize + scope.$index + 1}}</span>
				</template>
</el-table-column> -->
			<!-- <el-table-column label="操作" fixed="right">
      <template slot-scope="props">
        <el-button type="primary" @click="handleCheck1(props.row)">查看</el-button>
      </template>
    </el-table-column> -->


			<el-table-column type="expand">
				<template slot-scope="props">
					<!-- 内层为用户列表数组 -->
					<el-table :data="props.row.orderDetailList" style="width: 100%">
						<el-table-column label="商品主图" prop="mainImage">
							<template slot-scope="scope">
								<img :src="$http.publicUrl(scope.row.mainImage)" width="50" height="50">
							</template>
						</el-table-column>
						<el-table-column prop="goodsName" label="商品名称"></el-table-column>
						<el-table-column prop="specList" label="商品规格" :formatter="formatSpecList"></el-table-column>
						<el-table-column prop="price" label="价格" :formatter="addUnit"></el-table-column>
						<el-table-column prop="number" label="购买数量" :formatter="formatNumber"></el-table-column>
						<el-table-column prop="subtotal" label="小计" :formatter="addUnit"></el-table-column>
					</el-table>
				</template>
			</el-table-column>

			<el-table-column prop="orderNo" label="订单编号"></el-table-column>
			<el-table-column prop="description" label="订单描述"></el-table-column>
			<el-table-column prop="goodsTotalPrice" label="订单总额">
				<template scope="scope">
					<span>{{ scope.row.goodsTotalPrice + scope.row.deliveryFee }}元</span>
				</template>
			</el-table-column>
			<el-table-column prop="paymentMode" label="支付方式">
				<template scope="scope">
					<span v-if="scope.row.paymentMode == 1">微信支付</span>
					<span v-else-if="scope.row.paymentMode == 2">平台余额</span>
					<span v-else-if="scope.row.paymentMode == 3">平台积分</span>
				</template>
			</el-table-column>
			<el-table-column prop="actualPrice" label="实付款" :formatter="addUnit"></el-table-column>
			<el-table-column prop="goodsTotalQuantity" label="商品总数量">
				<template scope="scope">
					<span>{{ scope.row.goodsTotalQuantity }}件</span>
				</template>
			</el-table-column>
			<el-table-column prop="remark" label="买家备注"></el-table-column>
			<el-table-column prop="goodsSource" label="发货源">
				<template scope="scope">
					<span v-if="scope.row.goodsSource == 1">拼多多</span>
					<span v-else-if="scope.row.goodsSource == 2">淘宝</span>
					<span v-else-if="scope.row.goodsSource == 3">京东</span>
				</template>
			</el-table-column>
			<el-table-column prop="goodsSourceOrderNo" label="发货单号"></el-table-column>
			<el-table-column prop="platformRemark" label="平台备注"></el-table-column>

			<el-table-column prop="contactRealname" label="联系人姓名" width="120"></el-table-column>
			<el-table-column prop="contactPhone" label="联系电话" width="120"></el-table-column>
			<el-table-column prop="contactProvince" label="派送地址" width="190">
				<template slot-scope="scope">
					{{ scope.row.contactProvince }} - {{ scope.row.contactCity }} - {{ scope.row.contactArea }} -
					{{ scope.row.contactStreet }} - {{ scope.row.contactHouseNumber }}
				</template>
			</el-table-column>
			<el-table-column prop="status" label="订单状态" width="100" :formatter="formatOrder"></el-table-column>
			<el-table-column prop="createTime" label="下单时间" :formatter="formatTime" width="190"></el-table-column>
			<el-table-column label="操作" fixed="right">
				<template slot-scope="scope">
					<el-button size="small" @click="gotoOtherPage('view', scope.row)">查看详情</el-button>
					<!-- <el-button size="small" @click="handleEdit(scope.row)">标记发货</el-button> -->
					<el-button size="small" @click="handleCheck(scope.row)">发货</el-button>
					<el-button size="mini" @click="handleCopy(scope.$index, scope.row)">复制</el-button>
					<el-button size="small" @click="handleCheckremark(scope.$index, scope.row)">修改备注</el-button>
					<!-- <el-button size="small" v-if="scope.row.status == 4" @click="openDialog(scope.row.id)">申诉处理</el-button> -->
					<el-button size="small" v-if="scope.row.status == 4 || scope.row.status == 5 || scope.row.status == 6" @click="handleReFund(scope.$index, scope.row)">退款</el-button>
					<!-- <el-button type="danger" size="small" @click="handleDel(scope.row.id)">删除</el-button> -->
				</template>
			</el-table-column>
		</el-table>

		<!--工具条-->
		<el-col :span="24" class="toolbar">
			<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
				:page-sizes="[10, 20, 50, 100]" :page-size="searchMsg.pageSize"
				layout="total, sizes, prev, pager, next, jumper" :total="total" style="float:right;">
			</el-pagination>
		</el-col>

		<!--编辑界面-->
		<el-dialog :title="dialogTitle" :visible.sync="editFormVisible" @close="editFormClose"
			:close-on-click-modal="false">
			<el-form size="small" :model="editForm" class="editForm" label-width="80px" style="width: 80%;">
				<el-form-item prop="dealadvise" label="处理意见">
					<el-input type="textarea" placeholder="处理意见" v-model="editForm.dealadvise"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button @click="dealOption">保存</el-button>
				</el-form-item>
			</el-form>
			<!-- <div slot="footer" class="dialog-footer">
				<el-button @click.native="editFormVisible = false">关闭</el-button>
			</div> -->
		</el-dialog>

		<!--处理dialog-->
		<el-dialog title="发货" :visible.sync="logisticsNoFormVisible" :close-on-click-modal="false">
			<el-form :model="logisticsNoEdit" label-width="150px" ref="logisticsNoEdit">
				<el-form-item label="快递类型" :label-width="formLabelWidth">
					<el-radio-group v-model="logisticsNoEdit.expressType">
						<el-radio :label="1">默认快递</el-radio>
						<el-radio :label="2">单独快递</el-radio>
					</el-radio-group>
				</el-form-item>
				<el-form-item label="快递单号" prop="logisticsNo" v-if="logisticsNoEdit.expressType == 1">
					<el-input v-model="logisticsNoEdit.logisticsNo" placeholder="请输入快递单号"></el-input>
				</el-form-item>
				<div v-if="logisticsNoEdit.expressType == 2">
					<el-form-item label="快递公司" :label-width="formLabelWidth">
						<el-radio-group v-model="logisticsNoEdit.expressCompany">
							<el-radio :label="1">京东</el-radio>
							<el-radio :label="2">顺丰</el-radio>
						</el-radio-group>
					</el-form-item>
					<div v-if="logisticsNoEdit.expressCompany == 1">
						<el-form-item label="订单来源" :label-width="formLabelWidth">
							<el-select v-model="logisticsNoEdit.orderOrigin" placeholder="请选择订单来源">
								<el-option label="快递B2C（小于30kg）" value="1"></el-option>
								<el-option label="快递B2C（大于于30kg）" value="4"></el-option>
							</el-select>
						</el-form-item>
						<el-form-item label="产品编码" :label-width="formLabelWidth">
							<el-select v-model="logisticsNoEdit.productCode" placeholder="请选择产品编码">
								<el-option label="京东标快" value="ed-m-0001"></el-option>
								<el-option label="京东特快" value="ed-m-0002"></el-option>
								<el-option label="生鲜标快" value="LL-HD-M"></el-option>
								<el-option label="生鲜特快" value="LL-SD-M"></el-option>
							</el-select>
						</el-form-item>
						<el-form-item label="重量(kg)" :label-width="formLabelWidth">
							<el-input v-model="logisticsNoEdit.weight" autocomplete="off"></el-input>
						</el-form-item>
						<el-form-item label="揽收方式" :label-width="formLabelWidth">
							<el-radio-group v-model="logisticsNoEdit.pickupType">
								<el-radio :label="1">上门取件</el-radio>
								<el-radio :label="2">自送</el-radio>
							</el-radio-group>
						</el-form-item>
						<el-form-item label="揽收时间" :label-width="formLabelWidth">
							<el-date-picker v-model="logisticsNoEdit.pickupTime" type="datetimerange"
								start-placeholder="揽收开始时间" end-placeholder="揽收结束时间">
							</el-date-picker>
						</el-form-item>
						<el-form-item label="派送方式" :label-width="formLabelWidth">
							<el-radio-group v-model="logisticsNoEdit.deliveryType">
								<el-radio :label="1">送货上门</el-radio>
								<el-radio :label="2">自提</el-radio>
							</el-radio-group>
						</el-form-item>
						<el-form-item label="配送时间" :label-width="formLabelWidth">
							<el-date-picker v-model="logisticsNoEdit.expectDeliveryTime" type="datetimerange"
								start-placeholder="配送开始时间" end-placeholder="配送结束时间">
							</el-date-picker>
						</el-form-item>
						<el-form-item label="订单备注" :label-width="formLabelWidth">
							<el-input type="textarea" :rows="2" placeholder="请输入备注" v-model="logisticsNoEdit.remark">
							</el-input>
						</el-form-item>
					</div>
				</div>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button size="small" @click.native="logisticsNoFormVisible = false">取消</el-button>
				<el-button type="primary" size="small" @click="logisticsNoEditSubmit">提交</el-button>
			</div>
		</el-dialog>

		<el-dialog title="物流配送" :visible.sync="logisticsDeliveryVisible">
			<el-form :model="form">


			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click="logisticsDeliveryVisible = false">取 消</el-button>
				<el-button type="primary" @click="logisticsDelivery()">确 定</el-button>
			</div>
		</el-dialog>

		<!--处理dialog-->
		<el-dialog title="备注" :visible.sync="remarkFormVisible" :close-on-click-modal="false">
			<el-form :model="remarkNoEdit" label-width="150px" ref="remarkNoEdit">
				<el-form-item label="发货源" prop="goodsSource">
					<el-select v-model="remarkNoEdit.goodsSource" class="minInput">
						<el-option label="拼多多" :value="1"></el-option>
						<el-option label="淘宝" :value="2"></el-option>
						<el-option label="京东" :value="3"></el-option>
					</el-select>
					<!-- <el-input v-model="logisticsNoEdit.logisticsNo" placeholder="请选择发货源"></el-input> -->
				</el-form-item>
				<el-form-item label="发货源订单编号" prop="goodsSourceOrderNo">
					<el-input v-model="remarkNoEdit.goodsSourceOrderNo" placeholder="发货源订单编号"></el-input>
				</el-form-item>
				<el-form-item label="备注" prop="platformRemark">
					<el-input type="textarea" v-model="remarkNoEdit.platformRemark" placeholder="备注"
						:rows="5"></el-input>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button size="small" @click.native="remarkFormVisible = false">取消</el-button>
				<el-button type="primary" size="small" @click.native="remarkNoEditSubmit">提交</el-button>
			</div>
		</el-dialog>



		<!--处理dialog-->
		<el-dialog title="退款" :visible.sync="refundFormVisible" :close-on-click-modal="false">

			<el-table :data="refundNoEdit.orderDetailList" style="width: 100%" @selection-change="handleSelectionChange">
				<el-table-column type="selection" width="55"></el-table-column>
				<el-table-column label="商品主图" prop="mainImage">
					<template slot-scope="scope">
						<img :src="$http.publicUrl(scope.row.mainImage)" width="50" height="50">
					</template>
				</el-table-column>
				<el-table-column prop="goodsName" label="商品名称"></el-table-column>
				<el-table-column prop="specList" label="商品规格" :formatter="formatSpecList"></el-table-column>
				<el-table-column prop="price" label="价格" :formatter="addUnit"></el-table-column>
				<el-table-column prop="number" label="购买数量" :formatter="formatNumber"></el-table-column>
				<el-table-column prop="subtotal" label="小计" :formatter="addUnit"></el-table-column>
				<el-table-column prop="refundQuantity" label="退款数量" :formatter="addUnit">
					<template slot-scope="scope">
						<el-input type="number" v-model="scope.row.refundQuantity" min="1"></el-input>
					</template>
				</el-table-column>
			</el-table>

			<br/>
			<el-form :model="refundNoEdit" label-width="150px" ref="refundNoEdit">
				<el-form-item label="是否自定义退款金额" prop="isCustomRefundAmount">
					<el-radio-group v-model="refundNoEdit.isCustomRefundAmount" size="medium">
						<el-radio-button label="1">是</el-radio-button>
						<el-radio-button label="0">否</el-radio-button>
					</el-radio-group>
				</el-form-item>

				<el-form-item label="退款金额" prop="customRefundAmount" v-if="refundNoEdit.isCustomRefundAmount == 1">
					<el-input type="number" v-model="refundNoEdit.customRefundAmount" placeholder="退款金额"></el-input>
				</el-form-item>

			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button size="small" @click.native="refundFormVisible = false">取消</el-button>
				<el-button type="primary" size="small" @click.native="refundNoEditSubmit">提交</el-button>
			</div>



		</el-dialog>


	</section>
</template>
<script>
export default {
	data() {
		return {
			pickerOptions: {
				shortcuts: [{
					text: '最近一周',
					onClick(picker) {
						const end = new Date();
						let start = new Date();
						start.setTime(end.getTime() - 1000 * 60 * 60 * 24 * 7);
						picker.$emit('pick', [start, end]);
					}
				}, {
					text: '最近两周',
					onClick(picker) {
						const end = new Date();
						let start = new Date();
						start.setTime(end.getTime() - 1000 * 60 * 60 * 24 * 14);
						picker.$emit('pick', [start, end]);
					}
				}, {
					text: '最近一月',
					onClick(picker) {
						const end = new Date();
						let start = new Date();
						start.setTime(end.getTime() - 1000 * 60 * 60 * 24 * 30);
						picker.$emit('pick', [start, end]);
					}
				}, {
					text: '最近三月',
					onClick(picker) {
						const end = new Date();
						let start = new Date();
						start.setTime(end.getTime() - 1000 * 60 * 60 * 24 * 30 * 3);
						picker.$emit('pick', [start, end]);
					}
				}, {
					text: '最近半年',
					onClick(picker) {
						const end = new Date();
						let start = new Date();
						start.setTime(end.getTime() - 1000 * 60 * 60 * 24 * 180);
						picker.$emit('pick', [start, end]);
					}
				}, {
					text: '最近一年',
					onClick(picker) {
						const end = new Date();
						let start = new Date();
						start.setTime(end.getTime() - 1000 * 60 * 60 * 24 * 30 * 12);
						picker.$emit('pick', [start, end]);
					}
				}, {
					text: '最近两年',
					onClick(picker) {
						const end = new Date();
						let start = new Date();
						start.setTime(end.getTime() - 1000 * 60 * 60 * 24 * 30 * 24);
						picker.$emit('pick', [start, end]);
					}
				}, {
					text: '最近三年',
					onClick(picker) {
						const end = new Date();
						let start = new Date();
						start.setTime(end.getTime() - 1000 * 60 * 60 * 24 * 30 * 36);
						picker.$emit('pick', [start, end]);
					}
				}]
			},
			searchMsg: {
				pageNo: 1,
				pageSize: 20
			},
			list: [],
			total: 0,
			listLoading: false,
			sels: [],//列表选中列
			editFormVisible: false,//编辑界面是否显示
			//编辑界面数据
			editForm: {},
			searchData: [],
			dealtype: '',
			dealId: '',
			dialogTitle: '申诉处理',
			//轮询
			timer: null,

			logisticsNoFormVisible: false,//检查处理界面是否显示
			logisticsNoEdit: {
				id: '',
				logisticsNo: '',
				expressType: 2,
				expressCompany: 1,
				weight: 1,
				orderOrigin: '1',
				productCode: 'LL-HD-M',
				pickupType: 1,
				pickupTime: [new Date(), new Date().setHours(new Date().getHours() + 1)],
				deliveryType: 1,
				expectDeliveryTime: [new Date(), new Date().setHours(new Date().getHours() + 1)],
				remark: ''
			},

			logisticsNoCopy: {
				contactRealname: '',
				contactPhone: '',
				contactProvince: '',
				contactCity: '',
				contactArea: '',
				contactStreet: '',
				contactHouseNumber: '',
			},

			remarkFormVisible: false,//检查处理界面是否显示
			remarkNoEdit: {
				id: '',
				goodsSource: '',
				goodsSourceOrderNo: '',
				platformRemark: '',

			},

			refundFormVisible: false,//检查处理界面是否显示
			refundNoEdit: {
				isCustomRefundAmount: 0
			},
			multipleSelection: [],

			logisticsDeliveryVisible: false,
			formLabelWidth: '120px',
			fullscreenLoading: false
		}
	},
	methods: { 
		handleCheckremark: function (index, row) {
			this.remarkFormVisible = true;
			this.remarkNoEdit.id = row.id;
			// this.$refs[remarkNoEdit].resetFields();
			// this.$data = this.$options.data();
			if (row) {
				this.remarkNoEdit = {
					id: row.id,
					goodsSourceOrderNo: row.goodsSourceOrderNo,
					platformRemark: row.platformRemark,
					goodsSource: row.goodsSource == 1 ? '拼多多' : row.goodsSource == 2 ? '淘宝' : row.goodsSource == 3 ? '京东' : '',

				}
			} else {
				this.remarkNoEdit = {
					goodsSource: '',
					goodsSourceOrderNo: '',
					platformRemark: '',

				}
			}
		},
		handleSelectionChange(val) {
			this.multipleSelection = val;
			console.log(this.multipleSelection);
		},
		handleReFund: function (index, row) {
			this.refundFormVisible = true;
			this.refundNoEdit.id = row.id;
			// this.$refs[remarkNoEdit].resetFields();
			// this.$data = this.$options.data();
			
			this.refundNoEdit.orderDetailList = row.orderDetailList;

			//会导致输入框的输入变迟钝，只有当失焦的时候输入才会生效
			this.refundNoEdit.orderDetailList.forEach(item => {  
				if (item.refundQuantity === undefined || item.refundQuantity === null) {  
					item.refundQuantity = 1; // 设置默认值
				}
			});  

			// alert(this.refundNoEdit.isCustomRefundAmount)
		},
		refundNoEditSubmit: function () {
			this.$refs.refundNoEdit.validate((valid) => {
				if (valid) {// 编辑
					let vue = this;
					let param = Object.assign({}, this.refundNoEdit);

					if(this.multipleSelection.length == 0){
						vue.$message({
							showClose: true,
							message: '请选择要关联的商品',
							type: 'error'
						});
						return false							
					}

					//生成商品id数组
					var orderRefundGoodsList = [];
					for(let i = 0; i < this.multipleSelection.length; i++){
						var orderRefundGoods = {};
						orderRefundGoods.orderDetailId = this.multipleSelection[i].id;
						orderRefundGoods.number = this.multipleSelection[i].number;
						orderRefundGoodsList[i] = orderRefundGoods;
					}
					
					delete param.orderDetailList
					param.orderRefundGoodsList = orderRefundGoodsList;
					param.orderRefund = {};
					param.orderRefund.refundReasonDescription = "平台管理员手动退款";
					//todo - 退款金额暂时不填，由后端自己计算

					let url = '/rest/admin/pointsMall/order/applyAfterSalesDelivered/onlyRefund';
					vue.$http.post(vue, url, param,
						(vue, data) => {
							// this.editLoading = false;
							if (data.success) {
								vue.$message({
									showClose: true,
									message: data.message,
									type: 'success'
								});
								vue.getList()
								vue.refundFormVisible = false;
							}
						}, (error, data) => {
							// vue.logisticsNoFormVisible = false;
							vue.$message({
								showClose: true,
								message: data.message,
								type: 'error'
							});
						}
					)
				}
			});
		},

		handleCheck(row) {
			this.logisticsNoFormVisible = true;
			this.logisticsNoEdit.id = row.id;

			//单独快递配置项
			this.logisticsNoEdit.remark = row.remark;
			this.rowData = row;
			// 获取当前日期和时间
			var currentDate = new Date();
			// 获取当前小时数
			var currentHours = currentDate.getHours();
			// 当前小时数加一
			var newHours = currentHours + 1;
			// 设置新的小时数到当前日期和时间对象
			var pickupTime = new Date().setHours(newHours);
			this.logisticsNoEdit.pickupTime = [currentDate, new Date(pickupTime).toISOString()];
			this.logisticsNoEdit.expectDeliveryTime = [currentDate, new Date(pickupTime).toISOString()];
		},
		handleCopy(index, row) {
			this.logisticsNoCopy.contactRealname = row.contactRealname;
			this.logisticsNoCopy.contactPhone = row.contactPhone;
			this.logisticsNoCopy.contactProvince = row.contactProvince;
			this.logisticsNoCopy.contactCity = row.contactCity;
			this.logisticsNoCopy.contactArea = row.contactCity;
			this.logisticsNoCopy.contactStreet = row.contactStreet;
			this.logisticsNoCopy.contactHouseNumber = row.contactHouseNumber


			if (this.logisticsNoCopy.contactHouseNumber == null) {
				this.logisticsNoCopy.contactHouseNumber = " ";
			}
			//alert(this.logisticsNoCopy.contactRealname);
			this.copyContent = this.logisticsNoCopy.contactRealname + '   ' + this.logisticsNoCopy.contactPhone + '   ' + this.logisticsNoCopy.contactProvince + " " + this.logisticsNoCopy.contactCity + " " + this.logisticsNoCopy.contactStreet + " " + this.logisticsNoCopy.contactHouseNumber

			var input = document.createElement("input");
			input.value = this.copyContent; // 设置内容
			document.body.appendChild(input); // 添加临时实例
			input.select(); // 选择实例内容
			document.execCommand("Copy"); // 执行复制
			document.body.removeChild(input); // 删除临时实例
			if (document.execCommand("Copy")) {
				this.$message({
					message: '复制成功',
					type: 'success'
				});
			} else {
				this.$message({
					message: '复制失败',
					type: 'warning'
				});
			}
		},

		logisticsNoEditSubmit: function () { // 编辑
			let vue = this;
			let param = Object.assign({}, this.logisticsNoEdit);
			if (this.logisticsNoEdit.expressType == 2) {
				let row = this.rowData;
				if (this.logisticsNoEdit.expressCompany != 1) {
					vue.$message({
						showClose: true,
						message: "暂不支持该快递公司",
						type: 'error'
					});
					return
				}

			}
			if (this.logisticsNoEdit.expressType == 1) {
				if (param.logisticsNo == "") {
					vue.$message({
						showClose: true,
						message: "快递单号不能为空",
						type: 'error'
					});
					return false;
				}
			}
			const loading = this.$loading({
				lock: true,
				text: 'Loading',
				spinner: 'el-icon-loading',
				background: 'rgba(0, 0, 0, 0.7)'
			});
			let url = '/rest/admin/pointsMall/order/deliver';
			vue.$http.post(vue, url, param,
				(vue, data) => {
					loading.close();
					// this.editLoading = false;
					if (data.success) {
						vue.$message({
							showClose: true,
							message: data.message,
							type: 'success'
						});
						vue.getList()
						vue.logisticsNoFormVisible = false;
					}
				}, (error, data) => {
					loading.close();
					// vue.logisticsNoFormVisible = false;
					vue.$message({
						showClose: true,
						message: data.message,
						type: 'error'
					});
				}
			)
		},
		remarkNoEditSubmit: function () {
			this.$refs.remarkNoEdit.validate((valid) => {
				if (valid) {// 编辑

					let vue = this;
					let param = Object.assign({}, this.remarkNoEdit);

					//this.remarkNoEdit=[];


					// this.$refs[formRef].resetFields();
					// this.$data = this.$options.data();

					// alert(param.goodsSource)
					//param.goodsSource =  (param.goodsSource == '拼多多') ? 1 : (param.goodsSource == '淘宝') ? 2 : 3;
					// alert(param.goodsSource);
					if (param.goodsSource == "") {
						vue.$message({
							showClose: true,
							message: "发货源不能为空",
							type: 'error'
						});
						return false;
					}
					if (param.goodsSourceOrderNo == "") {
						vue.$message({
							showClose: true,
							message: "发货源订单编号不能为空",
							type: 'error'
						});
						return false;
					}
					if (param.platformRemark == "") {
						vue.$message({
							showClose: true,
							message: "平台备注不能为空",
							type: 'error'
						});
						return false;
					}
					let url = '/rest/admin/pointsMall/order/update';
					vue.$http.post(vue, url, param,
						(vue, data) => {
							// this.editLoading = false;
							if (data.success) {
								vue.$message({
									showClose: true,
									message: data.message,
									type: 'success'
								});
								vue.getList()
								this.remarkNoEdit = [];
								vue.remarkFormVisible = false;
							}
						}, (error, data) => {
							// vue.logisticsNoFormVisible = false;
							vue.$message({
								showClose: true,
								message: data.message,
								type: 'error'
							});
						}
					)
				}
			});
		},
		cellStyle({ row, column, rowIndex, columnIndex }) {
			return "text-align:center";
		},
		headerCellStyle({ row, rowIndex }) {
			return "text-align:center";
		},
		gotoOtherPage(type, row) {
			if (type === 'view') {
				this.$router.push({ path: 'pointsMall_orderDetail', query: { id: row.id } })
			}
		},
		dealOption() {
			let vue = this
			let url = ''
			let param = {
				id: vue.dealId,
				dealadvise: vue.editForm.dealadvise
			}
			vue.dealtype ? url = '/rest/admin/pointsMall/order/updateOrderByBack' : url = '/rest/admin/pointsMall/order/updateByDealadvise'
			vue.$http.post(vue, url, param,
				(vue, data) => {
					vue.$message({
						showClose: true,
						message: data.message,
						type: 'success'
					});
					vue.editFormVisible = false
					vue.getList()
				}, (error, data) => {
					vue.$message({
						showClose: true,
						message: data.message,
						type: 'error'
					});
				}
			)
		},
		openDialog(id, type = 0) {
			this.editFormVisible = true
			this.dealId = id
			this.dealtype = type
			type ? this.dialogTitle = '退款' : '申诉处理'
		},
		editFormClose() {
			this.editForm = {}
		},
		addStand() { // 新增规格
			let vue = this
			let param = Object.assign({}, vue.editForm)
			let regEn = /^[1-9]\d*$/;
			if (!regEn.test(param.sort)) {
				vue.$message({
					showClose: true,
					message: '输入正整数序号',
					type: 'error'
				});
				return false
			}
			if (!param.stand) {
				vue.$message({
					showClose: true,
					message: '请输入规格',
					type: 'error'
				});
				return false
			}
			vue.$http.post(vue, '/rest/admin/pointsMall/stand/update', param,
				(vue, data) => {
					vue.$message({
						showClose: true,
						message: data.message,
						type: 'success'
					});
					vue.editFormVisible = false
					vue.getList()
				}, (error, data) => {
					vue.$message({
						showClose: true,
						message: data.message,
						type: 'error'
					});
				}
			)
		},
		addUnit(row, column) { // 添加单位
			return (row[column.property] || 0) + '元'
		},
		formatDescription(row, column) { // 添加单位
			//let replaceReg = new RegExp("&nbsp;", 'g');
			//return row.description.replace(/1/g, " ");
			if (row.description != undefined) {
				return row.description.replace(/&nbsp;/g, " ")
			} else {
				return "-";
			}
		},
		formatTime(row, column) {
			let date = new Date(row[column.property]);
			return this.$utils.formatDate(date, 'yyyy-MM-dd hh:mm');
		},
		formatOrder(row, column) { // 0-待发货 1-待收货 2已完成 3-已取消 4-申诉中 5-已退款 6-申诉已完成
			let status = row[column.property]
			switch (status) {
				case 1:
					return '未付款'
					break;
				case 4:
					return '待发货'
					break;
				case 5:
					return '已发货'
					break;
				case 6:
					return '已完成'
					break;
				case 7:
					return '售后处理中'
					break;
				case 8:
					return '已退款'
					break;
				case 9:
					return '售后处理完成'
					break;
				case 10:
					return '已取消(未支付)'
					break;
			}
		},
		handleSizeChange(val) {
			this.searchMsg.pageSize = val;
			this.getList();
		},
		handleCurrentChange(val) {
			this.searchMsg.pageNo = val;
			this.getList();
		},
		formatSpecList(row, column) { // 添加单位
			let specStr = '';
			let specList = JSON.parse(row.specList);
			// specList.forEach(function(value, index){
			// 	console.log(value + "  " + specList[value]);
			// })
			// console.log(specList);
			if (specStr == '') {
				specStr = '-';
			}
			for (var key in specList) {
				//console.log(key + "-" + specList[key]);
				if (specStr == '') {

					specStr += specList[key];
				} else {
					specStr += '/' + specList[key];

				}
			}

			return specStr;
		},
		getList(pageNoParam) { // 获取列表
			if (pageNoParam) {
				this.searchMsg.pageNo = pageNoParam;
			} // 获取订单列表
			let vue = this
			let param = Object.assign({}, vue.searchMsg)

			//处理开始日期、结束日期
			if (vue.searchMsg.createTime) {
				let startDate = vue.searchMsg.createTime[0];
				let endDate = vue.searchMsg.createTime[1];
				param.startCreateTime = this.$utils.formatDate(new Date(startDate), 'yyyy/MM/dd hh:mm:ss');
				param.endCreateTime = this.$utils.formatDate(new Date(endDate), 'yyyy/MM/dd hh:mm:ss');
				delete param.createTime;
			}

			//只查询status=4 待发货     
			param.status = 4;

			vue.listLoading = true;
			vue.$http.post(vue, '/rest/admin/pointsMall/order/listWithDetail', param,
				(vue, data) => {
					vue.list = data.data.records
					let listWithDetail = data.data.records
					let str = '';
					for (let i = 0; i < listWithDetail.length; i++) {
						let WithDetail = listWithDetail[i];
						let specStr = '';
						let orderDetail = WithDetail.orderDetailList;

						for (let i = 0; i < orderDetail.length; i++) {

							let specList = orderDetail.specList;

							for (let key in specList) {

								if (specStr == '') {
									specStr += specList[key];
								} else {
									specStr += '/' + specList[key];
								}
							}
							str += '{"goodsName": "' + orderDetail.goodsName + '", "specList": "(' + specStr + ')", "number": "' + orderDetail.number + '", "subtotal": "' + orderDetail.subtotal + '"},';
						}

					}
					vue.total = data.data.total
					vue.listLoading = false;
				}, (error, data) => {
					vue.listLoading = false;
					vue.$message({
						showClose: true,
						message: data.message,
						type: 'error'
					});
				}
			)
		},
		handleDel(id) { // 删除
			this.$confirm('确认删除该记录吗?', '提示', {
				type: 'warning'
			}).then(() => {
				// this.listLoading = true;
				let vue = this;
				vue.$http.post(vue, '/rest/admin/pointsMall/stand/deleteById', { id },
					function (vue, data) {
						vue.$message({
							showClose: true,
							message: data.message,
							type: 'success'
						});
						vue.getList()
					}, function (error, data) {
						vue.$message({
							showClose: true,
							message: data.message,
							type: 'error'
						});
					}
				)
				// this.listLoading = false;
			}).catch(() => { });
		},
		handleEdit(row) { // 显示编辑界面
			let vue = this;
			let param = {
				id: row.id,
				flag: 3
			}
			vue.$http.post(vue, '/rest/admin/pointsMall/order/updateStatus', param,
				function (vue, data) {
					vue.$message({
						showClose: true,
						message: data.message,
						type: 'success'
					});
					vue.getList()
				}, function (error, data) {
					vue.$message({
						showClose: true,
						message: data.message,
						type: 'error'
					});
				}
			)
		},
		logisticsDelivery() { // 显示编辑界面
			let vue = this;
			let row = this.rowData;
			if (this.logisticsNoEdit.expressCompany != 1) {
				vue.$message({
					showClose: true,
					message: "暂不支持该快递公司",
					type: 'error'
				});
				return
			}
			const loading = this.$loading({
				lock: true,
				text: 'Loading',
				spinner: 'el-icon-loading',
				background: 'rgba(0, 0, 0, 0.7)'
			});
			let param = {
				id: row.id,
				flag: 3,
				expressType: this.logisticsNoEdit.expressType,
				expressCompany: this.logisticsNoEdit.expressCompany,
				orderOrigin: this.logisticsNoEdit.orderOrigin,
				productCode: this.logisticsNoEdit.productCode,
				weight: this.logisticsNoEdit.weight,
				pickupType: this.logisticsNoEdit.pickupType,
				pickupTime: this.logisticsNoEdit.pickupTime,
				deliveryType: this.logisticsNoEdit.deliveryType,
				expectDeliveryTime: this.logisticsNoEdit.expectDeliveryTime,
				remark: this.logisticsNoEdit.remark
			}
			vue.$http.post(vue, '/rest/merchant/order/logisticsDelivery', param,
				function (vue, data) {
					loading.close();
					vue.$message({
						showClose: true,
						message: data.message,
						type: 'success'
					});
					vue.getList()
				}, function (error, data) {
					loading.close();
					vue.$message({
						showClose: true,
						message: data.message,
						type: 'error'
					});
				}
			)
		}
	},
	mounted() {
		this.getList();
		//每隔一分钟轮询一次
		this.timer = setInterval(this.getList, 60 * 1000);
		//开启订单自动打印定时器
		this.$orderPrint.init();
	},
	beforeDestroy() {
		//清除定时任务，否则切换到其他页面，这定时任务依旧会执行
		clearInterval(this.timer);
	},
	handleCheck1(row) {
		const $table = this.$refs.table

		$table.toggleRowExpansion(row)
		$table.toggleRowSelection(row)
	}

}


</script>

<style scoped>
.el-button+.el-button {
	margin-top: 5px;
	margin-left: 0;
}

.editForm .el-input {
	width: 300px;
}

.editForm .minInput {
	width: 240px;
}
</style>